//
//  TravelCollectionViewCell.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/22.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "TravelCollectionViewCell.h"
#import "TravelLikeButton.h"
@interface TravelCollectionViewCell()
@property (nonatomic, strong)UIImageView * contentImage;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)TravelLikeButton * likeBtn;
@property (nonatomic, strong)NSString * travelID;
@end
@implementation TravelCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {

        [self.contentView addSubview:self.contentImage];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.likeBtn];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }return self;
}

- (UIButton *)likeBtn{
    if (!_likeBtn) {
        _likeBtn = [[TravelLikeButton alloc] init];
        [_likeBtn setImage:[UIImage imageNamed:@"icon_shoucang"] forState:UIControlStateNormal];
        [_likeBtn setImage:[UIImage imageNamed:@"icon_yishoucang"] forState:UIControlStateSelected];
        [_likeBtn setBackgroundColor:[UIColor clearColor]];
        [_likeBtn setTitle:@"3321" forState:UIControlStateNormal];
        _likeBtn.titleLabel.font = DEF_FontSize_14;
        [_likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_likeBtn addTarget:self action:@selector(likeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _likeBtn.selected = YES;
    }return _likeBtn;
}

- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.text = @"hahah";
        _contentLab.font = DEF_FontSize_14;
        _contentLab.textColor = [UIColor blackColor];
        _contentLab.textAlignment = NSTextAlignmentLeft;
//        _contentLab.backgroundColor = [UIColor yellowColor];
    }return _contentLab;
}

- (UIImageView *)contentImage{
    if (!_contentImage) {
        _contentImage = [[UIImageView alloc] init];
        [_contentImage setImage:[UIImage imageNamed:@"img_list2111"]];
    }return _contentImage;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    int border = 10/HEIGHT_5S_SCALE;
//    int labH = 60/HEIGHT_5S_SCALE;
    int imageH = 140/HEIGHT_5S_SCALE;
    int btnW = 60/WIDTH_5S_SCALE;
    int btnH = 20/HEIGHT_5S_SCALE;
    self.contentImage.frame = CGRectMake(0, 0, SCREEN_WIDTH, imageH/HEIGHT_5S_SCALE);
//    self.contentLab.frame = CGRectMake(border / 2, self.contentImage.bottom, SCREEN_WIDTH - border, labH);
    self.contentLab.frame = CGRectMake(border, self.contentImage.bottom + 5/WIDTH_5S_SCALE, SCREEN_WIDTH - border, [self.delegate getLabelHeightWithText:self.contentLab.text width:SCREEN_WIDTH - border font:14]);
    self.likeBtn.frame = CGRectMake(SCREEN_WIDTH - border - btnW, self.contentImage.bottom - border - btnH, btnW, btnH);

}

- (void)likeBtnClick:(UIButton *)btn{
    NSLog(@"收藏");
//    btn.selected = !btn.selected;
//    btn.selected = YES;
    if (self.travelNoteCollectBlock) {
        self.travelNoteCollectBlock(self.likeBtn);
    }
}

- (void)setModelData:(TravelCollectionModelData *)modelData{
    _modelData = modelData;
    self.contentLab.text = modelData.title;
    [self.contentImage sd_setImageWithURL:[NSURL URLWithString:modelData.pic1]];
    [self.likeBtn setTitle:modelData.likes forState:UIControlStateNormal];
    self.travelID = modelData.travelID;
}

@end
